package com.alisls.shequtao.service.goods.web;

import com.alisls.shequtao.service.goods.dto.GoodsDTO;
import com.alisls.shequtao.service.goods.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商品管理
 *
 * @author Ke Wang
 */
@Api(tags = "商品管理")
@RestController
@RequestMapping("/goods")
@AllArgsConstructor
@Slf4j
public class GoodsController {

    private final GoodsService goodsService;

    @GetMapping("/getGoodsBySpuId/{spuId}")
    public ResponseEntity<GoodsDTO> getGoodsBySpuId(@PathVariable("spuId") Long spuId) {
        return ResponseEntity.ok(new GoodsDTO());
    }

    @ApiOperation(value = "保存商品")
    @PostMapping("/saveGoods")
    public ResponseEntity<GoodsDTO> saveGoods(@RequestBody @Valid GoodsDTO goodsDTO) {
        goodsService.saveSpuWithSkus(goodsDTO);
        return ResponseEntity.ok(goodsDTO);
    }

}
